import { defineStore } from 'pinia';
import { usePersistedRef } from '@/hooks/usePersistence';

interface IRiskData {
  [key: string]: any;
}

export interface IModelData {
  [key: string]: any;
}

export const useIntelligentAnalyticsStore = defineStore('intelligentAnalytics', () => {
  // 使用持久化的 ref
  const { state: modelData, clear: clearModelData } = usePersistedRef<IModelData>({}, { key: 'intelligent-analytics-model-data' });
  //是否是单独打开 如果是单独打开则清除所有的弹窗
  const isIndividuallyOpen = ref(false);
  const { state: riskData, clear: clearRiskData } = usePersistedRef<IRiskData>({}, { key: 'intelligent-analytics-risk-data' });
  const dataSource = ref([]);
  // 清除所有持久化数据的方法
  const clearAllPersistedData = () => {
    clearModelData();
    clearRiskData();
  };

  return {
    modelData,
    riskData,
    dataSource,
    isIndividuallyOpen,
    clearAllPersistedData
  };
});
